package kuonjisai;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class J02_Departments {

	
	
	public static void main(String[] args) {
		
		final String DRV = "oracle.jdbc.driver.OracleDriver";
		final String URL = "jdbc:oracle:thin:@112.216.253.125:1521:xe";
		final String USR = "cjhmasterola";
		final String PWD = "cjhmasterola";
		
		
		Connection conn = null;  //연결
		PreparedStatement pstmt = null;	//질의
		ResultSet rs = null;					// 결과
		String SQL = "select * from departments";
		
		
		try {
			
			Class.forName(DRV); // 객체생성
			conn = DriverManager.getConnection(URL, USR, PWD); //  연결
			pstmt = conn.prepareStatement(SQL);  // 실행할 질의
			rs = pstmt.executeQuery(); // 결과 받음
			
			if ( rs.next() ) {
			
				do {
					System.out.print( rs.getString( "department_id" ) );
					System.out.print( " / " );
					System.out.print( rs.getString( "department_name" ) );
					System.out.print( " / " );
					System.out.print( rs.getString( "manager_id" ) );
					System.out.print( " / " );
					System.out.println( rs.getString( "location_id" ) );
						
									
				}while ( rs.next() );
				
				
			}
			else {
				System.out.println( "데이트가 업쪄염~");
			}
			
					
			
		} catch ( Exception ex ) {
			ex.printStackTrace();
		} finally {
			
			if ( rs != null) try { rs.close(); rs = null; } catch ( Exception e) {}
			if ( pstmt != null) try { pstmt.close(); pstmt = null; } catch ( Exception e ) {}
			if ( conn != null) try { conn.close(); conn = null; } catch ( Exception e) {}
			
		}
		
		
		
		
	} // main

} //class
